<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="商品类型" prop="productCategoryName">
        <el-input v-model="form.productCategoryName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button   v-hasPermi="['ims:goodType:add']" type="primary" plain icon="el-icon-plus" @click="updateRow(0,{})">新增</el-button>
    <el-table
      v-loading="loading"
      :data="list"
      row-key="id"
      :tree-props="{children: 'productCategoryVoList', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="productCategoryName" label="商品类型"/>
      <el-table-column prop="remark" label="备注" align="center"/>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            v-hasPermi="['ims:goodType:add']"
            @click="updateRow(1,scope.row)"
          >新增
          </el-button>
          <el-button
            type="text"
            v-hasPermi="['ims:goodType:update']"
            @click="updateRow(2,scope.row)"
          >修改
          </el-button>
          <el-button
            type="text"
            v-hasPermi="['ims:goodType:delete']"
            @click="updateRow(3,scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <updateDialog ref="updateDialog" :gooTypeList="list" @ok="handleQuery"></updateDialog>
  </div>
</template>

<script>
import {listGoodType, deleteGoodType} from "../../../api/imsMng";
import updateDialog from "./updateDialog.vue";

export default {
  name:'GoodType',
  components: {updateDialog},
  data() {
    return {
      loading: false,
      list: [],
      form: {
        productCategoryName: '',
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('form')
      this.handleQuery()
    },
    getList() {
      this.loading = true
      listGoodType(this.form).then(res => {
        this.list = res.data
      }).finally(e => {
        this.loading = false
      })
    },
    updateRow(flag, row) {
      let form = JSON.parse(JSON.stringify(row))
      if (flag == 0) {
        this.$refs.updateDialog.show(flag, form)
      }
      if (flag == 1) {
        form.superCategoryId = form.id
        form.id = ''
        form.productCategoryName = ''
        form.remark = ''
        this.$refs.updateDialog.show(flag, form)
      }
      if (flag == 2) {
        this.$refs.updateDialog.show(flag, form)
      }
      if (flag == 3) {
        this.$modal.confirm('是否确定删除').then(() => {
          deleteGoodType(row.id).then(res => {
            this.handleQuery()
            this.$message.success('删除成功')
          })
        })
      }
    }
  }
}
</script>
